package tron.config;

import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.serializer.ToStringSerializer;

import java.util.Arrays;
import java.util.HashMap;

@Configuration
public class TronKafkaConfig {

    @Bean
    public KafkaTemplate<String,Object> kafkaTemplate() {
        HashMap<String, Object> config = new HashMap<>();
        config.put("bootstrap.servers", Arrays.asList("192.168.2.135:9092"));
        DefaultKafkaProducerFactory<String,Object> producerFactory = new DefaultKafkaProducerFactory<String, Object>(config,
               StringSerializer::new ,ToStringSerializer::new
        );
        return new KafkaTemplate<>(producerFactory);
    }
}
